function oLoadEngine(engine) {
  this.engine = engine;
}

oLoadEngine.prototype = {
  // 获取前端八爪鱼框架配置，此处因为是初始化所以不能使用tips、template引擎。

  //cdn单页面引入echarts图表方法
  loadBaiduMap() {
    console.log("初始化百度地图脚本...");
    const BMap_URL = "https://api.map.baidu.com/api?v=1.0&type=webgl&ak=" + this.engine.config.api.baidu.MapAK + "&callback=onBMapCallback";

    let scriptNode = document.createElement("script");
    scriptNode.setAttribute("type", "text/javascript");
    scriptNode.setAttribute("src", BMap_URL);
    document.body.appendChild(scriptNode);

    // let color = document.createElement("script");
    // color.setAttribute("type", "text/javascript");//需要引入第三方库：redalert,googlelite,grassgreen,midnight,pink,darkgreen,bluish,grayscale,hardedge
    // color.setAttribute("src", 'http://developer.baidu.com/map/custom/stylelist.js');
    // document.body.appendChild(color);
    return new Promise((resolve, reject) => {
      // 百度地图异步加载回调处理
      window.onBMapCallback = function () {
        console.log("百度地图脚本初始化成功...");
        resolve(BMapGL);
      };

    });
  },
  loadBaiduMap3() {
    console.log("初始化百度地图脚本...");
    const BMap_URL = "https://api.map.baidu.com/api?v=2.0&ak=" + this.engine.config.api.baidu.MapAK + "&callback=onBMapCallback";

    let scriptNode = document.createElement("script");
    scriptNode.setAttribute("type", "text/javascript");
    scriptNode.setAttribute("src", BMap_URL);
    document.body.appendChild(scriptNode);

    // let color = document.createElement("script");
    // color.setAttribute("type", "text/javascript");//需要引入第三方库：redalert,googlelite,grassgreen,midnight,pink,darkgreen,bluish,grayscale,hardedge
    // color.setAttribute("src", 'http://developer.baidu.com/map/custom/stylelist.js');
    // document.body.appendChild(color);
    return new Promise((resolve, reject) => {
      // 百度地图异步加载回调处理
      window.onBMapCallback = function () {
        console.log("百度地图脚本初始化成功...");
        resolve(BMap);
      };

    });
  },
  loadHotMap() {
    return new Promise((resolve, reject) => {
      this.loadBaiduMap3().then((BMap) => {
        // alert(BMap);
        const HMap_URL = "http://api.map.baidu.com/library/Heatmap/2.0/src/Heatmap_min.js";
        let scriptNode = document.createElement("script");
        scriptNode.setAttribute("type", "text/javascript");
        scriptNode.setAttribute("src", HMap_URL);
        document.body.appendChild(scriptNode);
        scriptNode.onload = function () {
          setTimeout(function () {
            resolve(BMap);
          }, 100);
        }
      });
    });
  },
  //cdn单页面引入echarts图表方法
  loadGaodeMap() {
    return new Promise((resolve, reject) => {
      if (window.AMap) {
        resolve(window.AMap)
      } else {
        let script = document.createElement('script')
        script.type = 'text/javascript'
        script.async = true
        script.src = 'https://webapi.amap.com/maps?v=1.4.15&callback=initAMap&key=44ec367c4ac887f5ecca44cc558a5de0'
        script.onerror = reject
        document.body.appendChild(script)
        window.initAMap = () => {
          resolve(window.AMap)
        }
      }
    })
  },
  //cdn单页面引入echarts图表方法
  loadEcharts(callback) {
    let script = document.createElement('script'); //创建标签
    script.id = 'echartsScript'; //标签id
    script.type = 'text/javascript'; //标签id
    // script.src = 'https://cdn.bootcdn.net/ajax/libs/echarts/4.9.0-rc.1/echarts.min.js'; //添加src链接
    script.src = '../../../../static/resource/script/component/echarts/echarts.min.4.9.js'; //添加src链接
    document.head.append(script); //插入body中

    // 触发回调事件。
    script.onload = function () {
      // 加载完成后延迟100毫秒加载。
      setTimeout(function () {
        callback();
      }, 100);
    };
  },

  //cdn单页面引入echarts图表方法
  loadEcharts5(callback) {
    let script = document.createElement('script'); //创建标签
    script.id = 'echartsScript'; //标签id
    script.type = 'text/javascript'; //标签id
    // script.src = 'https://cdn.jsdelivr.net/npm/echarts@5.2.0/dist/echarts.min.js'; //添加src链接
    script.src = '../../../../static/resource/script/component/echarts/echarts.min.5.2.js'; //添加src链接
    if (script.addEventListener) {
      script.addEventListener('load', function () {
        callback();
      }, false);
    } else if (script.attachEvent) {
      script.attachEvent('onreadystatechange', function () {
        let target = window.event.srcElement;
        if (target.readyState == 'loaded') {
          callback();
        }
      });
    }
    document.head.append(script); //插入body中
  },
}

export {
  oLoadEngine
}


